package com.stark.wechat.context;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

import com.stark.wechat.job.PushJobQueueDailyJob;

/**
 * 初始化 Bean （项目启动）时自定义业务逻辑。
 * @author Ben
 * @since 1.0.0
 * @version 1.0.0, 2017/8/5
 */
@Component
public class CustomBeanPostProcessor implements BeanPostProcessor {
	@Override
	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
		return bean;
	}
	
	@Override
	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
		// 实例：项目启动时执行 job 作业
		if (bean instanceof PushJobQueueDailyJob) {
			PushJobQueueDailyJob job = (PushJobQueueDailyJob) bean;
			job.execute();
	    }
		
		return bean;
	}  
}